@extends('admin::layouts.master')
@section('title')
    修改表单
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" lay-filter="form_edit">

                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>模块</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <select name="cate_id">
                            @foreach( $data as $key=>$vo )
                                <option value="{{$vo['id']}}">{{$vo['title']}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>当前问题所属模块
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>问题</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input type="text" id="title" placeholder="请输入问题" name="title" required="" lay-verify="required" autocomplete="off" class="layui-input" maxlength="50"></div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>最多填写50个字符
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>排序</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input type="text" id="sort" placeholder="请输入排序" value="" name="sort"  lay-verify="number" autocomplete="off" class="layui-input"></div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>200以内数字
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red">*</span>回答</label>
                    <div class="layui-input-block">
                        {!! baidu_ueditor( $arr_data['content'] ) !!}
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <input type="hidden" name="id" >
                    <button class="layui-btn" lay-filter="add" lay-submit="">修改</button></div>
            </form>
        </div>
    </div>
@endsection

@section('tab_js')
    <script>
        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //监听提交
            form.on('submit(add)', function (data) {
                var form_data = data.field;
                if(form_data.cate_id.length <= 0){
                    layer.msg('请选择模块');
                    return false;
                }
                if(typeof form_data.content == 'undefined'){
                    layer.msg('请填写回答');
                    return false;
                }

                if(form_data.content.length <= 0){
                    layer.msg('请填写回答');
                    return false;
                }

                $.ajax({
                    url: js_url('admin_helpcenter_qaq_edit_do'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg(result.msg, {time: 600, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;

            });
            form.val('form_edit',{
                "id": '{{$arr_data['id']}}',
                "cate_id": '{{$arr_data['cate_id']}}',
                "title": '{{$arr_data['title']}}',
                "sort": '{{$arr_data['sort']}}',
            })

        });
    </script>
@endsection